<?php

namespace frontend\models;

use Yii;
use yii\db\ActiveRecord;
use yii\db\Query;
use yii\behaviors\TimestampBehavior;
use yii\db\Exception;
/**
 * This is the model class for table "District".
 *
 */
class District extends ActiveRecord
{
    public $type;//操作类型

    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%district}}';
    }



    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            TimestampBehavior::className(),
        ];
    }


    /**
     * 获取省市对应code
     * @param $province_code
     * @param $city_code
     * @author hey_heyang(635870453@qq.com)
     * @return array
     */
    public function getDistrictIdByCode($province_code,$city_code){
        $province_info = $this->find()->where(['front_code'=>$province_code,'deleted_at'=>null])->asArray()->one();
        $city_info = $this->find()->where(['front_code'=>$city_code,'deleted_at'=>null])->asArray()->one();
        if(empty($province_info) || empty($city_info)){
            return array('error'=>'省市地址不能为空!');
        }else{
            return array('province_id'=>$province_info['id'],'city_id'=>$city_info['id'],);
        }


    }


}
